import html_outputer
from mapping import read_maria


class GetTop(object):
    def __init__(self):
        self.getCsv = read_maria.ReadMaria()
        self.tomaria = html_outputer.HtmlOutputer()

    def get_csv(self):
        day = '\'2017-03-25\''
        hour = '\'21点\''
        sql = "SELECT * FROM desc_rooms2 WHERE DATE = {0} AND HOUR = {1}".format(day, hour)
        data_csv = self.getCsv.get_data(sql)
        # print(data_csv)
        return data_csv

    def top20(self):
        data_csv = self.get_csv()
        data_csv = data_csv.drop_duplicates('name')
        csv_top20 = data_csv.sort_values(by
                                         ='looks', ascending=False).head(20)
        print(csv_top20)
        # self.tomaria.to_maria(csv_top20, db_name='djangodb', table_name='blog_top20')
        csv_top20.to_csv('top20.csv', index=False)

        return csv_top20


if __name__ == '__main__':
    GTop = GetTop()
    GTop.top20()
